import path from 'path';
import nodeExternals from 'webpack-node-externals';
import merge from 'webpack-merge';

import pathConfig from '../config/path';
import baseConfig from './webpack.config.base';
import staticConfig from './webpack.config.static';

export default merge.smart(baseConfig, staticConfig, {
	target: 'node',
  mode: 'development',
  entry: path.join(pathConfig.clientPath,'ssr-server.js'),
  output: {
    filename: 'ssr-server.js',
    path: pathConfig.distPath,
    publicPath: '/public/',
    // 打包后的文件如果要在服务端运行必须写下面的规则 不然会出现module is not defined
    libraryTarget: 'commonjs2', 
  },
  externals: [nodeExternals()],
  module: {
    rules: [{
        test: /\.css$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
              localIdentName: '[name]_[local]--[hash:base64:5]',
              modules: true
            }
          },
          // 'postcss-loader'
        ]
      },
      // {
      //   test: /\.less$/, // antd 中的样式
      //   use: [
      //     'css-loader',
      //     {
      //       loader: 'less-loader',
      //       options: {
      //         paths: [pathConfig.antdPath],
      //         javascriptEnabled: true,
      //         modifyVars: {
      //           'primary-color': '#03b39b'
      //         }
      //       }
      //     }
      //   ]
      // }
    ]
  }
})
